﻿#include <iostream>
#include <set>
#include <string>
using namespace std;
class Person
{
public:
	string m_Name;
	int m_Age;
	Person(string name, int age)
	{
		this->m_Age = age;
		this->m_Name = name;
	}
};
class Mycompare 
{
public:
	bool operator()(const Person& p1,const Person& p2)const
	{
		//按照年龄进行降序
		return p1.m_Age > p2.m_Age;
	}
};
void test01()
{
	//自定义数据类型，都会指定排序规则

	set<Person,Mycompare>s;
	//创建一些Person对象
	Person p1("刘备", 24);
	Person p2("赵云", 32);
	Person p3("张飞", 39);
	Person p4("关羽", 28);
	s.insert(p1);
	s.insert(p2);
	s.insert(p3);
	s.insert(p4);
	for (set<Person,Mycompare>::iterator it = s.begin(); it != s.end(); it++)
	{
		cout << "姓名为:" << it->m_Name <<"   "<< "年龄为:" << it->m_Age << endl;
	}
}
int main()
{
	test01();
}